home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / msn / Msnifier.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  2KB  |  76 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. __author__ = 'dotSyntax'
  6. import itertools
  7. from time import sleep
  8. from types import GeneratorType as generator
  9. import logging
  10. from util import PriorityQueue, TimeOut, default_timer
  11. log = logging.getLogger('msn.msnifier')
  12.  
  13. class Msnifier(TimeOut):
  14.     
  15.     def __init__(self, socket):
  16.         TimeOut.__init__(self)
  17.         self.to_send = None
  18.         self.socket = socket
  19.         self.queue = PriorityQueue()
  20.  
  21.     
  22.     def send_pkt(self, pkt, priority = 5):
  23.         self._cv.__enter__()
  24.         
  25.         try:
  26.             self.queue.append(pkt, priority)
  27.         finally:
  28.             pass
  29.  
  30.  
  31.     
  32.     def compute_timeout(self):
  33.         if self._finished:
  34.             self._last_computed = -1
  35.         else:
  36.             self._last_computed = 5
  37.             pkt = self.next_pkt()
  38.             if pkt is not None:
  39.                 self._last_computed = self.socket.time_to_send(str(pkt))
  40.                 self.queue.append(iter([
  41.                     pkt]), priority = 1)
  42.             
  43.         return self._last_computed
  44.  
  45.     
  46.     def process(self):
  47.         pkt = self.next_pkt()
  48.         if pkt is not None:
  49.             self.socket._send(str(pkt))
  50.         
  51.  
  52.     
  53.     def next_pkt(self):
  54.         pkt = None
  55.         q = self.queue
  56.         while pkt is None and q:
  57.             
  58.             try:
  59.                 x = q.peek()
  60.                 
  61.                 try:
  62.                     pkt = x.next()
  63.                 except AttributeError:
  64.                     pkt = q.next()
  65.  
  66.             continue
  67.             except (GeneratorExit, StopIteration, ValueError):
  68.                 q.next()
  69.                 continue
  70.             
  71.  
  72.             None<EXCEPTION MATCH>(GeneratorExit, StopIteration, ValueError)
  73.         return pkt
  74.  
  75.  
  76.